package response

import "github.com/gogf/gf/net/ghttp"

const (
	RES_SUCCESS int = 0  //成功
	RES_UNKNOW  int = -1 //未知错误
)

type JsonResData struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func ToSuccess(r *ghttp.Request, interData interface{}) {
	ToCusResponse(r, RES_SUCCESS, "成功", interData)
}

func ToFail(r *ghttp.Request, nCode int, strMsg string) {
	ToCusResponse(r, nCode, strMsg, nil)
}

func ToCusResponse(r *ghttp.Request, nCode int, strMsg string, interData interface{}) {
	r.Response.WriteJson(JsonResData{
		Code: nCode,
		Msg:  strMsg,
		Data: interData,
	})
	r.Exit()
}
